﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThanhTu.GNC.Media.KQXS.DataAccess.DO;
using Oracle.ManagedDataAccess.Client;
using System.Data;

namespace ThanhTu.GNC.Media.KQXS.DataAccess.DAL
{
    public class StyleLotteryDAL : BaseDAL
    {
        public StyleLotteryDAL() : base() { }
        public int update(StyleLotteryDO vStyleLotteryDO)
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "STYLELOTTERY_PKG.SAVELOTTERYSTYLE";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("IN_SETTING_NAME", OracleDbType.Varchar2);
                oraParam.Value = vStyleLotteryDO.Settingname;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_SETTING_TYPE", OracleDbType.Varchar2);
                oraParam.Value = vStyleLotteryDO.Settingtype;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_POSITION", OracleDbType.Varchar2);
                oraParam.Value = vStyleLotteryDO.Position;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_SETTING_VALUE", OracleDbType.Varchar2);
                oraParam.Value = vStyleLotteryDO.Settingvalue;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.Int32);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);

                int result = ExecuteNoneQuery(oraComm);

                if (!Convert.IsDBNull(oraComm.Parameters["OUTRETURN"]))
                { result = Convert.ToInt32(oraComm.Parameters["OUTRETURN"].Value.ToString()); }

                oraComm.Dispose();
                oraParam = null;

                return result;
            }
        }
        public DataTable SelectAll()
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "STYLELOTTERY_PKG.GETLOTTERYSTYLE";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.RefCursor);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);

                using (DataSet ds = GetDataSet(oraComm))
                {
                    DataTable dt = null;

                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];

                        }
                    }

                    return dt;
                }
            }
        }
        public DataTable getbyPosition(string Position)
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "STYLELOTTERY_PKG.GETLOTTERYSTYLE_POSITION";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("IN_POSITION", OracleDbType.Varchar2);
                oraParam.Value = Position;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.RefCursor);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);


                using (DataSet ds = GetDataSet(oraComm))
                {
                    DataTable dt = null;

                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];

                        }
                    }

                    return dt;
                }
            }
        }
    }
}
